#include <stdio.h>

void sum_rows(int va[3][4], int vb);
void sum_cols(int va[3][4], int vb);
int sum2d(int va[3][4], int vb);

int main()
{
    /*1169:	f3 0f 1e fa          	endbr64 
    116d:	55                   	push   %rbp
    116e:	48 89 e5             	mov    %rsp,%rbp
    1171:	48 83 ec 40          	sub    $0x40,%rsp
    1175:	64 48 8b 04 25 28 00 	mov    %fs:0x28,%rax
    117c:	00 00 
    117e:	48 89 45 f8          	mov    %rax,-0x8(%rbp)
    1182:	31 c0                	xor    %eax,%eax
    1184:	c7 45 c0 02 00 00 00 	movl   $0x2,-0x40(%rbp)
    118b:	c7 45 c4 04 00 00 00 	movl   $0x4,-0x3c(%rbp)
    1192:	c7 45 c8 06 00 00 00 	movl   $0x6,-0x38(%rbp)
    1199:	c7 45 cc 08 00 00 00 	movl   $0x8,-0x34(%rbp)
    11a0:	c7 45 d0 03 00 00 00 	movl   $0x3,-0x30(%rbp)
    11a7:	c7 45 d4 05 00 00 00 	movl   $0x5,-0x2c(%rbp)
    11ae:	c7 45 d8 07 00 00 00 	movl   $0x7,-0x28(%rbp)
    11b5:	c7 45 dc 09 00 00 00 	movl   $0x9,-0x24(%rbp)
    11bc:	c7 45 e0 0c 00 00 00 	movl   $0xc,-0x20(%rbp)
    11c3:	c7 45 e4 0a 00 00 00 	movl   $0xa,-0x1c(%rbp)
    11ca:	c7 45 e8 08 00 00 00 	movl   $0x8,-0x18(%rbp)
    11d1:	c7 45 ec 06 00 00 00 	movl   $0x6,-0x14(%rbp)*/

	int a[3][4] = {
		{2, 4, 6, 8}, {3, 5, 7, 9},{12, 10, 8, 6} 
	};

    /*11d8:	48 8d 45 c0          	lea    -0x40(%rbp),%rax
    11dc:	be 03 00 00 00       	mov    $0x3,%esi
    11e1:	48 89 c7             	mov    %rax,%rdi
    11e4:	e8 50 00 00 00       	callq  1239 <sum_rows>*/
	sum_rows(a, 3);

    /*11e9:	48 8d 45 c0          	lea    -0x40(%rbp),%rax
    11ed:	be 03 00 00 00       	mov    $0x3,%esi
    11f2:	48 89 c7             	mov    %rax,%rdi
    11f5:	e8 bc 00 00 00       	callq  12b6 <sum_cols>*/
	sum_cols(a, 3);

    /*11fa:	48 8d 45 c0          	lea    -0x40(%rbp),%rax
    11fe:	be 03 00 00 00       	mov    $0x3,%esi
    1203:	48 89 c7             	mov    %rax,%rdi
    1206:	e8 28 01 00 00       	callq  1333 <sum2d>
    120b:	89 c6                	mov    %eax,%esi
    120d:	48 8d 3d f0 0d 00 00 	lea    0xdf0(%rip),%rdi        # 2004 <_IO_stdin_used+0x4>
    1214:	b8 00 00 00 00       	mov    $0x0,%eax
    1219:	e8 52 fe ff ff       	callq  1070 <printf@plt>*/
	printf("%d\n", sum2d(a, 3));

    /*121e:	b8 00 00 00 00       	mov    $0x0,%eax
    1223:	48 8b 55 f8          	mov    -0x8(%rbp),%rdx
    1227:	64 48 33 14 25 28 00 	xor    %fs:0x28,%rdx
    122e:	00 00 
    1230:	74 05                	je     1237 <main+0xce>
    1232:	e8 29 fe ff ff       	callq  1060 <__stack_chk_fail@plt>
    1237:	c9                   	leaveq 
    1238:	c3                   	retq   */
	return 0;
}

void sum_rows(int va[3][4], int vb)
{
    /*1239:	f3 0f 1e fa          	endbr64 
    123d:	55                   	push   %rbp
    123e:	48 89 e5             	mov    %rsp,%rbp
    1241:	48 83 ec 20          	sub    $0x20,%rsp
    1245:	48 89 7d e8          	mov    %rdi,-0x18(%rbp)	// va
    1249:	89 75 e4             	mov    %esi,-0x1c(%rbp)	// vb
    124c:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%rbp) */
	int a = 0;

    /*1253:	eb 55                	jmp    12aa <sum_rows+0x71>

    1255:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%rbp)
    125c:	c7 45 f8 00 00 00 00 	movl   $0x0,-0x8(%rbp)*/
	int b = 0;
	int c = 0;
	
    /*1263:	eb 22                	jmp    1287 <sum_rows+0x4e>
    1265:	8b 45 f4             	mov    -0xc(%rbp),%eax	// eax=a
    1268:	48 98                	cltq   
    126a:	48 c1 e0 04          	shl    $0x4,%rax		// rax=a<<4
    126e:	48 89 c2             	mov    %rax,%rdx		// rdx=rax
    1271:	48 8b 45 e8          	mov    -0x18(%rbp),%rax	// rax=va
    1275:	48 01 c2             	add    %rax,%rdx		// rdx=va+a<<4
    1278:	8b 45 f8             	mov    -0x8(%rbp),%eax	// eax=c
    127b:	48 98                	cltq   
    127d:	8b 04 82             	mov    (%rdx,%rax,4),%eax	// eax=(va+a<<4)+c<<2
    1280:	01 45 fc             	add    %eax,-0x4(%rbp)	// b = b+(va+a<<4)+c<<2
    1283:	83 45 f8 01          	addl   $0x1,-0x8(%rbp)	// c+1
    1287:	83 7d f8 03          	cmpl   $0x3,-0x8(%rbp)	// 3?=c
    128b:	7e d8                	jle    1265 <sum_rows+0x2c>

    128d:	8b 55 fc             	mov    -0x4(%rbp),%edx	// b
    1290:	8b 45 f4             	mov    -0xc(%rbp),%eax	// a
    1293:	89 c6                	mov    %eax,%esi
    1295:	48 8d 3d 82 0d 00 00 	lea    0xd82(%rip),%rdi        # 201e <_IO_stdin_used+0x1e>
    129c:	b8 00 00 00 00       	mov    $0x0,%eax
    12a1:	e8 ca fd ff ff       	callq  1070 <printf@plt>

    12a6:	83 45 f4 01          	addl   $0x1,-0xc(%rbp)	// a+1
    12aa:	8b 45 f4             	mov    -0xc(%rbp),%eax	// eax=a
    12ad:	3b 45 e4             	cmp    -0x1c(%rbp),%eax	// vb?=a
    12b0:	7c a3                	jl     1255 <sum_rows+0x1c>*/

	for (a = 0; a < vb; a++) {
		b = 0;
		for (c = 0; c <= 3; c++) {
			b += va[a][c];
		}	// - - -

		printf("%d %d\n", a, b);
	}

    /*12b2:	90                   	nop
    12b3:	90                   	nop
    12b4:	c9                   	leaveq 
    12b5:	c3                   	retq   */
}

void sum_cols(int va[3][4], int vb)
{
    /*12b6:	f3 0f 1e fa          	endbr64 
    12ba:	55                   	push   %rbp
    12bb:	48 89 e5             	mov    %rsp,%rbp
    12be:	48 83 ec 20          	sub    $0x20,%rsp
    12c2:	48 89 7d e8          	mov    %rdi,-0x18(%rbp)	// va
    12c6:	89 75 e4             	mov    %esi,-0x1c(%rbp)	// vb
    12c9:	c7 45 f8 00 00 00 00 	movl   $0x0,-0x8(%rbp)*/
	int a = 0;

    /*12d0:	eb 57                	jmp    1329 <sum_cols+0x73>*/

    /*12d2:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%rbp)
    12d9:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%rbp)*/
		int b = 0, c = 0;

    /*12e0:	eb 22                	jmp    1304 <sum_cols+0x4e>
    12e2:	8b 45 f4             	mov    -0xc(%rbp),%eax	// eax=c
    12e5:	48 98                	cltq   
    12e7:	48 c1 e0 04          	shl    $0x4,%rax	// rax=c<<4
    12eb:	48 89 c2             	mov    %rax,%rdx	// rdx=rax
    12ee:	48 8b 45 e8          	mov    -0x18(%rbp),%rax	// rax=va
    12f2:	48 01 c2             	add    %rax,%rdx		// rdx=va+c<<4
    12f5:	8b 45 f8             	mov    -0x8(%rbp),%eax	// eax=a
    12f8:	48 98                	cltq   
    12fa:	8b 04 82             	mov    (%rdx,%rax,4),%eax	// eax=va+c<<4+a<<2
    12fd:	01 45 fc             	add    %eax,-0x4(%rbp)		// b=b+va+c<<4+a<<2
    1300:	83 45 f4 01          	addl   $0x1,-0xc(%rbp)		// c+1
    1304:	8b 45 f4             	mov    -0xc(%rbp),%eax		// eax=c
    1307:	3b 45 e4             	cmp    -0x1c(%rbp),%eax		// vb?=c
    130a:	7c d6                	jl     12e2 <sum_cols+0x2c>

    130c:	8b 55 fc             	mov    -0x4(%rbp),%edx		// edx=b
    130f:	8b 45 f8             	mov    -0x8(%rbp),%eax		// eax=a
    1312:	89 c6                	mov    %eax,%esi			// esi=a
    1314:	48 8d 3d 16 0d 00 00 	lea    0xd16(%rip),%rdi        # 2031 <_IO_stdin_used+0x31>
    131b:	b8 00 00 00 00       	mov    $0x0,%eax
    1320:	e8 4b fd ff ff       	callq  1070 <printf@plt>
    1325:	83 45 f8 01          	addl   $0x1,-0x8(%rbp)		// a+1
    1329:	83 7d f8 03          	cmpl   $0x3,-0x8(%rbp)		// 3?=a
    132d:	7e a3                	jle    12d2 <sum_cols+0x1c>*/
	for (a = 0; a <=3 ; a++) {
		b = 0;
		for (c = 0; c < 3; c++) {
			b += va[c][a];
		}	// | | | |

		printf("%d %d\n", a, b);
	}

    /*132f:	90                   	nop
    1330:	90                   	nop
    1331:	c9                   	leaveq 
    1332:	c3                   	retq   */
}

int sum2d(int va[3][4], int vb)
{
    /*1333:	f3 0f 1e fa          	endbr64 
    1337:	55                   	push   %rbp
    1338:	48 89 e5             	mov    %rsp,%rbp
    133b:	48 89 7d e8          	mov    %rdi,-0x18(%rbp)	// va
    133f:	89 75 e4             	mov    %esi,-0x1c(%rbp)	// vb
    1342:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%rbp)
    1349:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%rbp)*/
	int a = 0;
	int b = 0;

    /*1350:	eb 35                	jmp    1387 <sum2d+0x54>*/

    /*1352:	c7 45 f8 00 00 00 00 	movl   $0x0,-0x8(%rbp)*/
	int c = 0;

    /*1359:	eb 22                	jmp    137d <sum2d+0x4a>

    135b:	8b 45 f4             	mov    -0xc(%rbp),%eax	// eax=b
    135e:	48 98                	cltq   
    1360:	48 c1 e0 04          	shl    $0x4,%rax		// rax=b<<4
    1364:	48 89 c2             	mov    %rax,%rdx		// rdx=rax
    1367:	48 8b 45 e8          	mov    -0x18(%rbp),%rax	// rax=va
    136b:	48 01 c2             	add    %rax,%rdx		// rdx=va+b<<4
    136e:	8b 45 f8             	mov    -0x8(%rbp),%eax	// eax=c
    1371:	48 98                	cltq   
    1373:	8b 04 82             	mov    (%rdx,%rax,4),%eax	// eax=va+b<<4+c<<2
    1376:	01 45 fc             	add    %eax,-0x4(%rbp)	// a=a+va+b<<4+c<<2
    1379:	83 45 f8 01          	addl   $0x1,-0x8(%rbp)	// c+1
    137d:	83 7d f8 03          	cmpl   $0x3,-0x8(%rbp)	// 3?=c
    1381:	7e d8                	jle    135b <sum2d+0x28>

    1383:	83 45 f4 01          	addl   $0x1,-0xc(%rbp)	// b+1
    1387:	8b 45 f4             	mov    -0xc(%rbp),%eax	// eax
    138a:	3b 45 e4             	cmp    -0x1c(%rbp),%eax	// va?=b
    138d:	7c c3                	jl     1352 <sum2d+0x1f>*/
	for (b = 0; b < vb; b++) {
		for (c = 0; c <= 3; c++) {
			a += va[b][c];
		}
	}

    /*138f:	8b 45 fc             	mov    -0x4(%rbp),%eax	// a
    1392:	5d                   	pop    %rbp
    1393:	c3                   	retq   
    1394:	66 2e 0f 1f 84 00 00 	nopw   %cs:0x0(%rax,%rax,1)
    139b:	00 00 00 
    139e:	66 90                	xchg   %ax,%ax*/
	return a;
}
